-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto bind component data-test-* attributes #27
Conversation
@Turbo87: the preprocessor that strips |
@@ -1,6 +1,5 @@ | |||
/*jshint node:true*/ | |||
module.exports = { | |||
useVersionCompatibility: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcoow was this an intentional change? as discussed earlier today we should most likely test all minor Ember releases since we're using an Handlebars AST transform here and the AST is not public/stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was just a result of running ember init
after updating Ember CLI.
# Usually, it's ok to finish the test scenario without reverting | ||
# to the addon's original dependency state, skipping "cleanup". | ||
- ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup | ||
- npm run mocha |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is failing because there is no mocha
script defined. what's the reason for using mocha
if all you do is check JSHint compliance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, don't remember to be honest 😊
"ember-resolver": "^2.0.3", | ||
"loader.js": "^4.0.1", | ||
"ember-welcome-page": "^1.0.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is most likely not needed here
"ember-cli-babel": "^5.1.5", | ||
"lodash": "^4.0.0" | ||
"ember-cli-babel": "^5.1.7", | ||
"lodash": "^4.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra leading space here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
0cc827d
to
a22acce
Compare
a22acce
to
6de34db
Compare
@marcoow @pangratz I've updated this PR with a few changes:
|
6de34db
to
f2bc2da
Compare
It looks like the automatic binding of component attributes is failing on Ember 1.13 and 2.0. Do we care about compatibility with those releases? Should I investigate further if we might be able to work around this? |
} | ||
} | ||
|
||
set(component, 'attributeBindings', attributeBindings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally prefer component.set('attributeBindings', attributeBindings)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@Turbo87: I'd like to keep support for 1.13 if possible and certainly 2.0 unless that's really hard to do for some reason. |
... that reopens the Component class and automatically binds all data-test-* attributes
f2bc2da
to
151aad0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice ❤️
} | ||
} | ||
|
||
component.set('attributeBindings', attributeBindings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this doesn't work though if the original attributeBindings
is a CP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is true, but I'm not sure if attributeBindings
being a CP is supported by Ember at all. otherwise there would be no need for us to apply the bindDataTestAttributes()
function before the super constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point. Could you check this though?
that is true, but I'm not sure if attributeBindings being a CP is supported by Ember at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now checking if attributeBindings
is a computed property in the bindDataTestAttributes()
function and if so, I skip the automatic binding and display a warning message.
@marcoow I've figured out the problems with the early Ember versions: when used like |
|
||
return Ember.warn(message, false, { | ||
id: 'ember-test-selectors.computed-attribute-bindings', | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we could somehow make it work correctly in this case as well that would be awesome of course. In theory it should be possible to replace the CP with a wrapper one that we create of course but I'm not sure it's worth the added complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's worth the extra complexity to be honest. I've never seen anyone use a CP for attributeBindings
and I have quite a hard time coming up with use cases where that would be a good idea. I'd suggest keeping the warning for now, and if many users report that they are seeing this warning then we can still think about implementing it.
assert.equal(find('.test6').find('div[data-non-test]').length, 0, 'data-non-test does not exists'); | ||
}); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a test for the case where the component defines attributeBindings
(both as a string as well as an array) itself and that asserts that the data-test-*
attributes get merged with these correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcoow we test that in the unit tests for the bindDataTestAttributes()
function. Can attributeBindings
be a string? Unfortunately it's not documented anywhere but I've only found instances where it is used as an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, just assumed both might actually be supported. If we have a unit test for this already that should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since attributeBindings
is a concatenated property, the string will end up in an array eventually. This only works for:
attributeBindings: "myAttribute"
which will become
attributeBindings: ["myAttribute"]
and will not work for:
attributeBindings: "myAttribute myOtherAttribute"
which would result in attributeBindings: ["myAttribute myOtherAttribute"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://emberjs.com/api/classes/Ember.View.html#toc_html-attributes only uses arrays, so I'm assuming passing a string is not officially supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's not official API, I would tend to agree with @Turbo87 and not support this tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented a quick array wrapper now, see f48e6ad
This is the follow-up PR for #26.
Instead of automatically inserting
data-test-*
attributes for all components with the component's internal name as a value we're now simply auto-binding alldata-test-*
attributes that are present on a component.